﻿using CSRedis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSRedisTest
{
    class Program
    {

        private static readonly object _lock = new object();
        static int j = 0;
        static int maxj = 1_000_0000;
        static string key = "TestNum";
        static Random rnd = new Random((int)(DateTime.Now.Ticks / 10000));
        static CSRedisClient rds = new CSRedisClient("192.168.3.88:6380,defaultDatabase=0,poolsize=50,tryit=0");
        static void Main(string[] args)
        {
            
          
          
            //for (int i = 0; i < 100; i++)
            //{
            //    var sk = key + i;
             
            //    rds.Set(sk, sk);
            //}
            ////runpp();
            //Task.Run(() => runpp());
            //Task.Run(() => runpp());
            //Task.Run(() => runpp());
            rds.ScriptFlush();
            Console.ReadLine();
        }

        private static bool runpp()
        {
           
           while (true)
            {
                rnd = new Random((int)(DateTime.Now.Ticks / 10000));
                var rndkey = key + rnd.Next(1, 100);
                Console.WriteLine("rndkey:" + rds.Get(rndkey));
                lock (_lock)
                {
                    j++;
                    if (j >= maxj)
                    {
                        Console.WriteLine("已完成读取: " + j + "次");
                        return true;
                    }
                }

            }
        }
        
        /// <summary>
            /// 产生(min,max)之间均匀分布的随机数
            /// </summary>
            /// <param name="min"></param>
            /// <param name="max"></param>
            /// <returns></returns>
        public static double AverageRandom(double min, double max)
        {
            int MINnteger = (int)(min * 10000);
            int MAXnteger = (int)(max * 10000);
            int resultInteger = rnd.Next(MINnteger, MAXnteger);
            return resultInteger / 10000.0;
        }
    }
}
